package com.xuetang9.t9.hotel.services.impl;

import com.xuetang9.t9.hotel.beans.CommodityInfo;
import com.xuetang9.t9.hotel.beans.CommodityType;
import com.xuetang9.t9.hotel.mapper.ICommodityInfoMapper;
import com.xuetang9.t9.hotel.mapper.condition.impl.CommodityInfoCondition;
import com.xuetang9.t9.hotel.mapper.condition.impl.CommodityTypeCondition;
import com.xuetang9.t9.hotel.services.ICommodityExpenseService;
import com.xuetang9.t9.hotel.services.ICommodityInfoService;
import com.xuetang9.t9.hotel.utils.PageBean;
import com.xuetang9.t9.hotel.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommodityInfoServiceImpl implements ICommodityInfoService {

    @Autowired
    private ICommodityInfoMapper commodityInfoMapper;

    @Autowired
    private ICommodityExpenseService commodityExpenseService;


    @Override
    public boolean save(CommodityInfo commodityInfo) {
        if(commodityInfo == null){
            return false;
        }
        return commodityInfoMapper.insert(commodityInfo) > 0;
    }

    @Override
    public boolean update(CommodityInfo commodityInfo) {
        if(commodityInfo == null){
            return false;
        }
        return commodityInfoMapper.update(commodityInfo) > 0;
    }

    @Override
    public boolean remove(Integer id) {
        if(null == id){
            return false;
        }
        commodityExpenseService.removeByCommId(id);
        return commodityInfoMapper.deleteById(id) > 0;
    }

    @Override
    public PageBean queryByAll(CommodityInfoCondition commodityInfoCondition) {
        if(commodityInfoCondition == null){
            commodityInfoCondition = new CommodityInfoCondition();
        }
        List<CommodityInfo> commodityInfos = commodityInfoMapper.selectByAll(commodityInfoCondition);
        PageBean pageBean = new PageBean();
        pageBean.ok(commodityInfos);
        pageBean.setCount(queryByCount(commodityInfoCondition));
        return pageBean;
    }

    @Override
    public Long queryByCount(CommodityInfoCondition commodityInfoCondition) {
        return commodityInfoMapper.selectByCount(commodityInfoCondition);
    }
}
